package sk.mka.phd.timit.maven;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;

/**
 * @author katrami
 * @date Dec 10, 2010
 */
public class TimitConfig {

    public final String CONFIG_FILENAME = "target/classes/config-logic.properties";
    public static final Logger log = Logger.getLogger(TimitConfig.class);
    public String dir;
    public String groupsOutputXml;
    public String groupsOutputRepresentation;
    public String phonemeDistribution;
    public String phonemeReduction;
    public String absPath;

    private TimitConfig() {
        try {
            init();
        } catch (Exception e) {
            log.error("Failed to initialize mobiledoc config", e);
        }
    }

    public static TimitConfig getInstance() {
        return NgramConfigHolder.INSTANCE;
    }

    public void init() {
        final Properties env = new Properties();
        try {
            env.load(new FileInputStream(CONFIG_FILENAME));
            absPath = System.getProperty("user.dir");
            dir = env.getProperty("dir");
            phonemeReduction = env.getProperty("phonemeReduction");
            phonemeDistribution = env.getProperty("phonemeDistribution");
            groupsOutputRepresentation = env.getProperty("groupsOutputRepresentation");
            groupsOutputXml = env.getProperty("groupsOutputXml");

        } catch (IOException ex) {
            log.debug(ex);
        }
    }

    public static class NgramConfigHolder {

        public static final TimitConfig INSTANCE = new TimitConfig();
    }
}
